package com.shixun.milktea.controller;


import com.shixun.milktea.entity.Consumer;
import com.shixun.milktea.entity.Order;
import com.shixun.milktea.service.OrderService;

import com.shixun.milktea.service.OrderdetailService;
import com.shixun.milktea.vo.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 黄志成
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单相关接口")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PutMapping("/updateOrder")
    @ApiOperation(value = "修改订单状态")
    public ResultVO updateOrder(@RequestBody Order order){
        return new ResultVO(orderService.updateOrder(order));
    }

    @GetMapping("/showOrderAndDetails")
    @ApiOperation(value = "查询所有订单")
    public ResultVO showAllOrder(){
        List<Order> res = orderService.getAllOrderAndDetails();
        return new ResultVO(res);
    }

    @GetMapping("/getOrderPageByPhone")
    @ApiOperation(value = "根据电话分页查询订单")
    public ResultVO getOrderByPhone(PhoneVo phoneVo){
        return new ResultVO(orderService.getOrderPageByPhone(phoneVo));
    }

    @GetMapping("/getOrderPage/{pageNo}/{pageSize}")
    @ApiOperation(value = "分页查询订单")
    public ResultVO getOrderPage(@PathVariable("pageNo") Integer pageNo,@PathVariable("pageSize")Integer pageSize){
        return new ResultVO(orderService.getOrderPage(pageNo, pageSize));
    }

    @GetMapping("/getSaleCount")
    @ApiOperation(value = "销售统计查询")
    public ResultVO getSaleCount(){
        List<SaleVo> saleCount = orderService.getSaleCount();
        return new ResultVO(saleCount);
    }


    @GetMapping("/findGroupFiveMt")
    @ApiOperation(value = "查询销量前五的奶茶")
    public ResultVO findOrderGroupFiveMt(){
        List<MtlistVo> mtlistVos = orderService.getGroupFiveMt();
        return new ResultVO(mtlistVos);
    }

    @GetMapping("/getOrderByConsumerId/{consumerId}")
    @ApiOperation(value = "根据消费id查询订单")
    public ResultVO getOrderByConsumerId(@PathVariable("consumerId")Integer consumerId){
        return new ResultVO(orderService.getOrderByConsumerId(consumerId));
    }


    @GetMapping("/getOrderByConsumerId/{consumerId}/{orderStatus}")
    @ApiOperation(value = "根据消费者id和状态查询订单")
    public ResultVO getOrderByConsumerId(@PathVariable("consumerId")Integer consumerId,@PathVariable("orderStatus") String orderStatus){
        return new ResultVO(orderService.getOrderByIdAndStatus(consumerId,orderStatus));
    }

    @PostMapping("/addNewOrder")
    @ApiOperation(value = "创建订单")
    public ResultVO addNewOrder(@RequestBody OrderVo orderVo){
        orderVo.setOrderTime(new Date());
        return new ResultVO(orderService.addNewOrder(orderVo));
    }
}
